<?php
    header("Access-Control-Allow-Origin: *");
    header("content-type:text/html;charset=utf-8");
    $servername = "localhost";
    $dbname = "app";
    $db_username = "root";
    $db_password = "";
    $device_list = array();
    $scene_list = array();
    // $cotroller_list = array();
    if($_GET["table"] == "device") {
        try {
            $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $db_username, $db_password,array
            (PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES'utf8';"));
            foreach ($dbh->query('SELECT * from device') as $row) { 
                array_push($device_list,$row);
            }
            echo json_encode($device_list,JSON_UNESCAPED_UNICODE);
            $dbh = null;
        } catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    } elseif ($_GET["table"] == "scene") {
        try {
            $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $db_username, $db_password,array
            (PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES'utf8';"));
            foreach ($dbh->query('SELECT * from scene') as $row) {
                array_push($scene_list,$row);
            }
            echo json_encode($scene_list,JSON_UNESCAPED_UNICODE);
            $dbh = null;
        } catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }
    ?>